package com.leetcode.partition4;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author `RKC`
 * @date 2022/2/13 10:08
 */
public class LC315计算右侧小于当前元素的个数 {

    private static final int N = 20010, offset = 10001;
    private static int[] c = new int[N];

    private static int n = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int[] nums = new int[ss.length];
        for (int i = 0; i < ss.length; i++) nums[i] = Integer.parseInt(ss[i]);
        writer.write(countSmaller(nums) + "\n");
        writer.flush();
    }

    public static List<Integer> countSmaller(int[] nums) {
        n = nums.length;
        List<Integer> answer = new ArrayList<>(n);
        for (int i = n - 1; i >= 0; i--) {
            int x = nums[i] + offset;
            answer.add(ask(x - 1));
            add(x, 1);
        }
        Collections.reverse(answer);
        return answer;
    }

    private static int ask(int x) {
        int res = 0;
        for (int i = x; i != 0; i -= lowbit(i)) res += c[i];
        return res;
    }

    private static void add(int x, int k) {
        for (int i = x; i < N; i += lowbit(i)) c[i] += k;
    }

    private static int lowbit(int x) {
        return x & -x;
    }
}
